package inter;

import symbols.Type;

public class While extends Stmt {
	Expr expr;
	Stmt stmt;
	int labelLoop;
	
	public While() {
		this.expr = null;
		this.stmt = null;
	}
	
	public void init(Expr x, Stmt s){
		this.expr = x;
		this.stmt = s;
		if(expr.type != Type.BOOL) expr.error("Expressao booleana requerida para o comadno while");
	}

	public void gen(int b, int a){
		after = a;
		expr.jumping(0, a);
		int label = newLabel();
		labelLoop = label;
		emitLabel(label);
		stmt.gen(label, b);
		emit("goto L" + b + ";");
	}
}
